#pragma once

#include "esp_spp_api.h"

/********configuration********/
#define SPP_SERVER_NAME "ESP_SPP_SERVER"  /* The name of the SPP server that is displayed to the remote device */
#define BT_DEVICE_NAME "ESP Local Server" /* The Bluetooth name displayed to the remote device */
#define BT_DEVICE_ONLY_ONE 0              /* Whether there can be only one connected device */

typedef struct
{
  esp_spp_cb_event_t event; /* 事件枚举 */
  esp_spp_cb_param_t param; /* 事件参数 */
} spp_event_t;

typedef struct
{
  uint8_t *data;
  size_t len;
  uint32_t handle; // 消息源的SPP句柄，如果是0，则是服务器主动发送广播
}spp_msg_t;

#if BT_DEVICE_ONLY_ONE
typedef struct
{
  uint32_t handle;     /* SPP 客户端句柄 为0表示无设备 */
  uint8_t write_state; /* SPP 消息发送状态 0:发送中 1:发送遇到堵塞 2:发送完毕*/
} spp_dev_t;

uint32_t get_spp_handle(void);
uint8_t get_spp_write_state(void);
void set_spp_write_state(uint8_t state);

#else
typedef struct _spp_dev_t
{
  uint32_t handle;                  /* SPP 客户端句柄 为0表示无设备 */
  uint8_t write_state;              /* SPP 消息发送状态 0:发送中 1:发送遇到堵塞 2:发送完毕 */
  uint8_t label; /* 设备类别标签 */ /* 在本程序中，代表机器人阵营 0:无阵营*/
  struct _spp_dev_t *next;
}spp_dev_t;


void spp_broadcast(spp_msg_t *msg);

#endif


char *bda2str(uint8_t *bda, char *str, size_t size);
uint8_t get_spp_clients_num(void);
void myBT_init(void);
